﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Drawing;
using GamePlugin.Logics.Core;
using System.Windows.Media;

namespace GamePlugin.Logics.Data.Auction
{
    public class AuctionItem : PluginObject
    {
        public AuctionItem()
        {
            this.Reset();
        }

        private void Reset()
        {
            this.IsExactDeadline = false;
            this.AuctionPrice = 0;
            this.ItemCounldBeFound = true;
        }

        public void UpdateDisplayName()
        {
            string prefix = "";
            if (this.IsExactDeadline)
                prefix = "時間確認";
            else
                prefix = "時間待查";
            this.DisplayName = prefix + " " + this.NamePrefix + "價格:" + Helper.GetChinesePrice(this.AuctionPrice) + " " + this.AuctionDeadline.ToString();
        }

        public void LoadImageFromDisk()
        {
            this.ImageSource = Helper.GetImageSource(ImageStorage.GetBitmap(this.ImagePath));
        }


        [Editable]
        public bool ItemCounldBeFound
        {
            get;
            set;
        }

        public static readonly DependencyProperty NamePrefixProperty =
            DependencyProperty.Register("NamePrefix", typeof(string), typeof(AuctionItem),
            new FrameworkPropertyMetadata(null, new PropertyChangedCallback(_OnNamePrefixChanged)));
        static void _OnNamePrefixChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            AuctionItem item = sender as AuctionItem;
            if (item != null)
                item.UpdateDisplayName();
        }
        [Editable]
        public string NamePrefix
        {
            get { return (string)GetValue(NamePrefixProperty); }
            set { SetValue(NamePrefixProperty, value); }

        }
        public static readonly DependencyProperty DisplayNameProperty =
            DependencyProperty.Register("DisplayName", typeof(string), typeof(AuctionItem), null);
        [Editable]
        public string DisplayName
        {
            get { return (string)GetValue(DisplayNameProperty); }
            set { SetValue(DisplayNameProperty, value); }
        }

        public static readonly DependencyProperty ImageSourceProperty =
            DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(AuctionItem),
            new FrameworkPropertyMetadata(null, new PropertyChangedCallback(_OnImageSourceChanged)));
        static void _OnImageSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
        }
        public ImageSource ImageSource
        {
            get { return (ImageSource)GetValue(ImageSourceProperty); }
            set { SetValue(ImageSourceProperty, value); }
        }

        public static readonly DependencyProperty AuctionPriceProperty =
            DependencyProperty.Register("AuctionPrice", typeof(int), typeof(AuctionItem),
            new FrameworkPropertyMetadata(0, new PropertyChangedCallback(_OnAuctionPriceChanged)));
        static void _OnAuctionPriceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            AuctionItem item = sender as AuctionItem;
            if (item != null)
                item.UpdateDisplayName();
        }
        [Editable]
        public int AuctionPrice
        {
            get { return (int)GetValue(AuctionPriceProperty); }
            set { SetValue(AuctionPriceProperty, value); }
        }


        public static readonly DependencyProperty ImagePathProperty =
            DependencyProperty.Register("ImagePath", typeof(string), typeof(AuctionItem), null);
        [Editable]
        public string ImagePath
        {
            get { return (string)GetValue(ImagePathProperty); }
            set { SetValue(ImagePathProperty, value); }
        }

        public static readonly DependencyProperty AuctionDeadlineProperty =
            DependencyProperty.Register("AuctionDeadline", typeof(DateTime), typeof(AuctionItem), null);
        [Editable]
        public DateTime AuctionDeadline
        {
            get { return (DateTime)GetValue(AuctionDeadlineProperty); }
            set { SetValue(AuctionDeadlineProperty, value); }
        }

        public static readonly DependencyProperty IsExactDeadlineProperty =
            DependencyProperty.Register("IsExactDeadline", typeof(bool), typeof(AuctionItem), null);
        [Editable]
        public bool IsExactDeadline
        {
            get { return (bool)GetValue(IsExactDeadlineProperty); }
            set { SetValue(IsExactDeadlineProperty, value); }
        }
    }
}
